package com.cskaoyan.wordmemorize.controller.app;

import com.cskaoyan.wordmemorize.auth.StpKit;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.app.DownLoadUserReviewDTO;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.UserReviewDataCommand;
import com.cskaoyan.wordmemorize.service.UserReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/review")
public class UserReviewController {
    @Autowired
    UserReviewService userReviewService;
    @PostMapping("voc")
    //**添加用户的单词复习数据(参数为用户已选单词的id集合)
    public Result addUserReviewData(@RequestBody List<Long> integers) {
        //获取用户id
        System.out.println(integers);
        Long userId = StpKit.USER.getLoginIdAsLong();
        userReviewService.addUserRovRev(integers,userId);
        return Result.ok();
    }

    //**下载用户的所有单词复习数据
     @GetMapping("data")
    public DownLoadUserReviewDTO downloadUserReviewData(PageRequest pageRequest) {
        Long userId = StpKit.USER.getLoginIdAsLong();
         DownLoadUserReviewDTO downLoadUserReviewDTO = userReviewService.downloadUserReviewData(pageRequest, userId);
         return downLoadUserReviewDTO;
     }
    @PostMapping("data")
    public Result synchronizeUserReviewData(@RequestBody UserReviewDataCommand json) {
        Long userId = StpKit.USER.getLoginIdAsLong();
        userReviewService.synchronizeUserReviewData(json, userId);
        return Result.ok();
    }
}
